<template>
	<view class="my-settle-container">
		<!-- 全选区域 -->
		<label class="radio">
			<radio color="#C00000" :checked="isTotalCheck" @click="allCheck" /><text>全选</text>
		</label>
		<!-- 合计区域 -->
		<view class="amount-box">
			合计:<text class="amount">{{totalPrice|price}}</text>
		</view>
		<!-- 结算按钮 -->
		<view class="btn-settle" @click="onSettle">结算({{settleGoodsTotal}})</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations,
		mapState
	} from 'vuex'
	export default {
		name: "my-settle",
		computed: {
			// 将 m_cart 模块中的 cart 数组映射到当前页面中使用
			...mapGetters('cartModule', ['goodsTotal', 'totalPrice', 'isTotalCheck', 'settleGoodsTotal']),
			...mapState('userInfo', ['userAddress','token']),
		},
		data() {
			return {
				second:3
			};
		},
		filters: {
			price(val) {
				return '￥' + Number(val).toFixed(2)
			}
		},
		methods: {
			...mapMutations('cartModule', ['updataCheckAll']),
			allCheck(e) {
				console.log(66666, e);
				this.updataCheckAll(!this.isTotalCheck)
			},
			onSettle() {
				let  timer;
				if (!this.settleGoodsTotal) return uni.showToast({
					title: '您未选择商品,请先选择商品!',
					duration: 1500,
					icon: 'none',
				})
				if(!this.userAddress.userName)return uni.showToast({
					title: '请选择收货地址!',
					duration: 1500,
					icon: 'none',
				})
				if(!this.token){
					uni.showToast({
						title: `您未登录,${this.second}秒后即将跳转到登录页面!`,
						duration: 1500,
						icon: 'none',
					})
					timer = setInterval(()=>{
						if(this.second<=1){
							clearInterval(timer)
							console.log('跳转登录页面');
							uni.switchTab({
								url: '/pages/my/my'
							});
							return 
						}
						this.second--
						uni.showToast({
							title: `您未登录,${this.second}秒后即将跳转到登录页面!`,
							duration: 1500,
							icon: 'none',
						})
					},1000)
				}
			}
		}

	}
</script>

<style lang="scss">
	.my-settle-container {
		/* 底部固定定位 */
		position: fixed;
		bottom: 0;
		left: 0;
		/* 设置宽高和背景色 */
		width: 100%;
		height: 50px;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.radio {
			display: flex;
			align-items: center;
			padding-left: 5px;
		}

		.amount {
			color: #c00000;
		}

		.btn-settle {
			height: 50px;
			min-width: 100px;
			background-color: #c00000;
			color: white;
			line-height: 50px;
			text-align: center;
			padding: 0 10px;
		}
	}
</style>
